<?php
/**
 * 会员评论
 * @return
 * @author yuncran@126.com
 */

namespace app\model;

use app\BaseModel;
use app\services\SendMessageServices;

class TrendsCommentModel extends BaseModel
{

    protected $pk = "id";

    protected $name = "trends_comment";

    protected $append = ['user'];


    public function getUserAttr($value, $data)
    {
        return UserModel::getUserInfoFind(['id' => $data['user_id']]);
    }


    /**
     * 处理新增事件 || 增加系统消息通知
     * @param $trends_comment
     * @return void
     * @author yuncran@126.com
     */
    public static function onAfterInsert($trends_comment)
    {
        $trends = TrendsModel::where('id', $trends_comment->trends_id)->field('id,user_id')->find();
        SendMessageServices::checkUserSendMessage($trends_comment->user_id, $trends->user_id, $type='trends_comment', $trends_comment->id);
    }
}